/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bean;

import ejb.OrderDetail;
import ejb.OrderDetailFacadeLocal;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author longdm0708l
 */
public class OrderDetailBean {

    public void createOrderDetail(OrderDetail orderDetail)
    {
        lookupOrderDetailFacade().create(orderDetail);
    }

    public void editOrderDetail(OrderDetail orderDetail)
    {
        lookupOrderDetailFacade().edit(orderDetail);
    }

    public void removeOrderDetail(OrderDetail orderDetail)
    {
        lookupOrderDetailFacade().remove(orderDetail);
    }

    private String OrderDetailId;

    public String getOrderDetailId() {
        return OrderDetailId;
    }

    public void setOrderDetailId(String OrderDetailId) {
        this.OrderDetailId = OrderDetailId;
    }

    public List<OrderDetail> getAllOrderDetail()
    {
        return lookupOrderDetailFacade().findAll();
    }

    public OrderDetail getOrderDetailById()
    {
        return lookupOrderDetailFacade().find(Integer.valueOf(getOrderDetailId()));
    }

    private OrderDetailFacadeLocal lookupOrderDetailFacade() {
        try {
            Context c = new InitialContext();
            return (OrderDetailFacadeLocal) c.lookup("java:comp/env/OrderDetailFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

}
